/**
 * 
 */
package org.gas.barapraja.proc;

import java.util.ArrayList;
import java.util.List;

/**
 * @author gilang
 *
 */
public abstract class PduProcessorContainer {
	
	private static List<PduProcessor> pduProcessors=new ArrayList<PduProcessor>();
	
	private static ProccessContainer container;
	
	public static ProccessContainer getContainerInstance(){
		if(container==null){
			container=createContainer();
			return container;
		}else{
			return container;
		}
	}

	private static ProccessContainer createContainer(){
		ProccessContainer container=new ProccessContainer() {
			
			
			public synchronized void addProcessor(PduProcessor processor){
				if(!pduProcessors.contains(processor)){
					pduProcessors.add(processor);
				}
			}
			
			
			public synchronized void remove(PduProcessor processor){
				if(pduProcessors.contains(processor)){
					pduProcessors.remove(processor);
				}
			}
			
		
			public synchronized PduProcessor get(int index){
				return pduProcessors.get(index);
			}
			
			
			public synchronized int count(){
				return pduProcessors.size();
			}
		};
		return container;
	}

}
